<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="text" placeholder="请输入0-100之间的整数" id="in">
<input type="button" value="猜一猜" onclick="f()">
<div>结果：<span></span></div>


<script>
    //得到0-100随机整数
    let x = parseInt(Math.random() * 101);
    console.log(x)
    let count = 0;
    function f(){
        let d = document.querySelector("span");
        let g = document.querySelector("#in");
        if(isNaN(g.value)){
            d.innerText = "输入错误";
            return ;
        }


        if(x > g.value){
            d.innerText = "小了";
            count++;
        }else if(x < g.value){
            d.innerText = "大了"
            count++;
        }else {
            d.innerText = "猜对了,共猜了" + count + 1 + "次";
        }

    }

</script>

</body>
</html>